#include "Adetector.h"


//bool GetFinalState(CDraw &para, TClonesArray *branchJet      ,TClonesArray *branchElectron ,TClonesArray *branchMuon     ,TClonesArray *branchPhoton   ,TClonesArray *branchMissingET,TClonesArray *branchParticle ,MyPlots* plots,
//		std::vector<Jet*> & Vjet,std::vector<Jet*>& Vbjet,std::vector<Jet*>& Vcjet,std::vector<Jet*>& Vqjet,std::vector<Jet*>& Vtaujet, std::vector<Jet*>& Vtagjet,std::vector<Jet*>& Vuntagjet,
//		std::vector<Electron*>& Velec,std::vector<Muon*>& Vmuon,std::vector<Jet*>& Vtau,std::vector<Photon*>& Vphoton,std::vector<MissingET*>& Vmet, AnalyseClass &analyse){

bool GetFinalState_detector(CDraw &para, AnalyseClass &analyse, AObject &object, MyPlots* plots){

	bool Jjet         = false;
	bool Jtagjet      = false;
	bool Jlep         = false;
	bool Jelec        = false;
	bool Jmuon        = false;
	bool Jmet         = false;
	bool Jphoton      = false;
	bool Jbasic       = false;

	if(para.jet.SWITCH ){
		GetFinalState_detector_jet(para,analyse,object, analyse.delphes.branchJet,plots,Jjet, Jtagjet);
		if(!Jjet||!Jtagjet){
			return(false);
		}
	}
	else{
		Jjet=true;
	    Jtagjet=true;
	}

	// Analyse elec 
	if(para.lep.SWITCH){
		GetFinalState_detector_lep(para,analyse, object, analyse.delphes.branchElectron, analyse.delphes.branchMuon, plots, Jlep, Jelec, Jmuon);
		if(!Jlep){
			return(false);
		}
	}
	else{
		Jelec = true;
		Jmuon = true;
		Jlep  = true;
	}

	// Analyse missing ET
	if(para.met.SWITCH){
		para.debug.Message(4,20,"get met");
		GetFinalState_detector_met(para,analyse, object,  analyse.delphes.branchMissingET,plots,object.Vmet, Jmet);
		para.debug.Message(4,20,"end get met",Jmet);
		if(!Jmet){
			ShowMessage(2,"met false");
			return(false);
		}
	}
	else{
		ShowMessage(2,"met default true");
		Jmet=true;
	}

	if(para.photon.SWITCH){
		para.debug.Message(4,20,"get photon");
		GetFinalState_detector_photon(para,analyse,object,  analyse.delphes.branchPhoton,plots,object.Vphoton, Jphoton);
		para.debug.Message(4,20,"end get photon",Jphoton);
		if(!Jphoton){
			return(false);
		}
	}
	else{
		Jphoton=true;
	}

	para.debug.Message(4,20,"fill Llep into Lvis",object.Llep.size());
	for(int i=0;i<object.Llep.size();i++){
		object.Lvis.push_back(object.Llep[i]);
	}
	para.debug.Message(4,20,"fill Ljet into Lvis",object.Ljet.size());
	for(int i=0;i<object.Ljet.size();i++){
		object.Lvis.push_back(object.Ljet[i]);
	}
	para.debug.Message(4,20,"fill Lphoton into Lvis",object.Lphoton.size());
	for(int i=0;i<object.Lphoton.size();i++){
		object.Lvis.push_back(object.Lphoton[i]);
	}
	std::sort(object.Lvis.begin(),object.Lvis.end(),TLV_compare_Pt);
	




	para.debug.Message(4,20,"in the detector: begin fill particle");
	if(para.flow.record_event){
		object.Fill_Particle(para,analyse);
	}

	//  number pass the all basic cuts;
	para.debug.Message(4,20,"get all basic cuts");
	if(Jjet&&Jtagjet&&Jlep&&Jmet&Jphoton){
		Jbasic=true;
		analyse.counter.getCounter("basic");
		return(true);
	}
	else{
		return(false);
	}

}












